package com.example.homework8.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.homework8.R;
import com.example.homework8.bean.TagBean;

import java.util.ArrayList;
import java.util.List;

public class TagAdapter2 extends BaseAdapter {

    private ArrayList<TagBean> mList = new ArrayList<>();
    private OnDelClickListener onDelClickListener;
    private int tag;
    private Context mcontext;

    public TagAdapter2(Context context, ArrayList<TagBean> lists) {
        this.mList = lists;
        this.mcontext = context;
    }
    public void setData(List<TagBean> mList){
        this.mList.clear();
        this.mList.addAll(mList);
        if (tag == 1){
            TagBean bean = new TagBean();
            bean.setId(-3);
            bean.setText("全部");
            this.mList.add(0,bean);
        }
        notifyDataSetChanged();
    }

    public void remove(int position){
        this.mList.remove(position);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return mList.get(i).getId();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View convertView = LayoutInflater.from(mcontext).inflate(R.layout.item_tag2,viewGroup,false);
        TextView textView = convertView.findViewById(R.id.text);
        textView.setText(mList.get(i).getText());

        if (mList.get(i).getSelected()){
            textView.setTextColor(Color.parseColor("#03A9F4"));
        }else{
            textView.setTextColor(Color.parseColor("black"));
        }
        return convertView;
    }

    public interface OnDelClickListener{
        void onDelClick(int position, TagBean bean);

        void onItemClick(int position, TagBean bean);
    }

    public void addOnDelClickListener(OnDelClickListener onDelClickListener){
        this.onDelClickListener = onDelClickListener;
    }

    static class ViewHolder extends RecyclerView.ViewHolder{

        private TextView text;
        private ImageView ivDel;

        public ViewHolder(View itemView) {
            super(itemView);
            text = itemView.findViewById(R.id.text);
            ivDel = itemView.findViewById(R.id.ivDel);
        }
    }
}
